<?php namespace Home\Controller;

use Framework\Kernel\Controller;
use Home\Model\User;
use Framework\Tool\Code;
class LoginController extends Controller
{
	protected $db;

	public function __init()
	{
		$this->db = new User;
	}

	public function reg()
	{
		if(!$this->db->reg()){
			$json =[
				'errcode'=>1,
				'message'=>$this->db->getError()
			];
			$this->ajax($json);
		}
		else
		{
			$json =[
				'errcode'=>0,
				'message'=>'注册成功',
				'data'=>'?'
			];
			$this->ajax($json);
		}
	}

	//会员登录
	public function login()
	{
		if(!$this->db->login()){
			$json =[
				'errcode'=>1,
				'message'=>$this->db->getError()
			];
			$this->ajax($json);
		}
		else
		{
			$json =[
				'errcode'=>0,
				'message'=>'登录成功',
				'data'=>'?'
			];
			$this->ajax($json);
		}
	}

	//显示验证码
	public function code()
	{
		(new Code)->show();
	}

	public function quit()
	{
		session_unset();
		session_destroy();
		header('location:?');
	}
}




















